#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;
int getday(int& year, int& month)
{
    int arr[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
    if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
    {
        return 29;
    }
    return arr[month];
}
void Test1()
{
    int year = 0, days = 0;
    int month = 0;
    scanf("%d %d", &year, &days);
 
    for (month = 1;days > getday(year, month);month++)
    {
        days -= getday(year, month);
    }
    cout << year << "-";
    if (month < 10)
    {
        cout << "0";
    }
    cout << month << "-";
    if (days < 10)
    {
        cout << "0";
    }
    cout << days << endl;
}
int getMonth_Day(int year, int month)
{
    int arr[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
    if (month == 2 && (year % 4 == 0 && year % 100 != 0 || (year % 400 == 0)))
    {
        return 29;
    }
    return arr[month];
}
void Test2()
{
    int m = 0;
    cin >> m;
    while (m--)
    {
        int year = 0, month = 0, day = 0, addDay = 0;
        cin >> year >> month >> day >> addDay;
        day += addDay;
        while (day > getMonth_Day(year, month))
        {
            day -= getMonth_Day(year, month);
            month++;
            if (month > 12)
            {
                month = 1;
                year++;
            }
        }
        cout << year << "-";
        if (month < 10)
        {
            cout << "0";
        }
        cout << month << "-";
        if (day < 10)
        {
            cout << "0";
        }
        cout << day << endl;
    }
}
int main()
{
    //Test1();
    Test2();
}